	 
**************************************************************************************	 
*Figure 2: The Effects of Postal Voting on the Probability of Turnout in Referendums  (Individual-level Data)
**************************************************************************************	 	 
	capture mkdir "marginal_effects"
	scalar year_up=2011	

	// groups with 2 categories


	
	local var "group_knowledge group_gender group_urban group_employed group_gov_trust group_interest group_language"
	foreach x of local var{   
	
	forvalues i=1(1)2{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)
	
	margins, at((mean)  _all) dydx(postal_all), if  `x'==(`i') // (c) marginal effects
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	

	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)

	keep beta1  beta_cov*
	keep if beta_cov1!=.
	saveold ./marginal_effects/me_postalmarginal_`x'`i'.dta, replace
	}
	
	use ./marginal_effects/me_postalmarginal_`x'1.dta, clear
	forvalues i=2(1)2{
	append using ./marginal_effects/me_postalmarginal_`x'`i'.dta
		}
	gen group=_n
	order beta11  beta_cov11 
	saveold ./marginal_effects/me_postalmarginal_`x'_all.dta, replace
	
	}
	
	// groups with 3 categories
	
	local var "group_educ group_age  group_orientation group_religion group_orientation_alt group_participation group_party group_income"
	foreach x of local var{   


	forvalues i=1(1)3{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)

	margins, at((mean)  _all) dydx(postal_all), if  `x'==(`i') // (c) marginal effects
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	

	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)

	keep beta1  beta_cov*
	keep if beta_cov1!=.
	saveold ./marginal_effects/me_postalmarginal_`x'`i'.dta, replace
	}
	
	use ./marginal_effects/me_postalmarginal_`x'1.dta, clear
	forvalues i=2(1)3{
	append using ./marginal_effects/me_postalmarginal_`x'`i'.dta
		}
	gen group=_n
	order beta11  beta_cov11 
	saveold ./marginal_effects/me_postalmarginal_`x'_all.dta, replace
	
	}
	
	

	// group with 5 categories
	
	
	local var "group_party_identification"
	foreach x of local var{   
	


	forvalues i=1(1)5{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)

	margins, at((mean)  _all) dydx(postal_all), if  `x'==(`i') // (c) marginal effects
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	

	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)

	keep beta1  beta_cov*
	keep if beta_cov1!=.
	saveold ./marginal_effects/me_postalmarginal_`x'`i'.dta, replace
	}
	

	use ./marginal_effects/me_postalmarginal_`x'1.dta, clear
	gen group=1
	forvalues i=2(1)5{
	append using ./marginal_effects/me_postalmarginal_`x'`i'.dta
	replace group=`i' if group==.
		}
	*gen group=_n
	order beta11  beta_cov11 
	saveold ./marginal_effects/me_postalmarginal_`x'_all.dta, replace
	
	}
	
	
	
	
	// append all groups
	
	use ./marginal_effects/me_postalmarginal_group_party_identification_all.dta, clear

	gen variable="group_party_identification"
	local count_var=1
	
	local new = _N + 1 // add one observation for labeling of group description
    set obs `new'  
	replace group=0 if group==.
	replace variable="group_party_identification" if variable==""
	gen var_sort=1
	gen variable_num=1
	
	local var "group_orientation group_interest group_knowledge group_gov_trust group_age group_educ group_employed group_income group_language group_religion group_urban"
	foreach x of local var{   // sample restriction 1: drop all with missing values
	local count_var=`count_var' +1
	append using ./marginal_effects/me_postalmarginal_`x'_all.dta
	local new = _N + 1 // add one observation for labeling of group description
    set obs `new'  
	replace group=0 if group==.
	replace var_sort=`count_var' if var_sort==.
	replace variable="`x'" if  variable==""
	replace variable_num=`count_var' if  variable_num==.
	}
	
	rename beta11 beta1
	rename beta_cov11 beta_cov1
	
	
	gen indi=_n
	
	reshape long beta beta_cov, i(indi) j(postal)
	
	gsort variable_num  -group postal // generate index for y-axis of plot
	gen id=_n
	
	// labeling
	
	gen group_description=""
	replace group_description="Ideology" if variable=="group_orientation"
	replace group_description="Political interest" if variable=="group_interest"
	replace group_description="Political knowledge" if variable=="group_knowledge"
	replace group_description="Trust in government" if variable=="group_gov_trust"
	replace group_description="Age" if variable=="group_age"
	replace group_description="Education" if variable=="group_educ"
	replace group_description="Employment status" if variable=="group_employed"
	replace group_description="Language" if variable=="group_language"
	replace group_description="Religion" if variable=="group_religion"
	replace group_description="Residence" if variable=="group_urban"
	replace group_description="Income" if variable=="group_income"
	replace group_description="Party identification" if variable=="group_party_identification"


	gen group_member_descr=""
	replace group_member_descr="Ideology:" if variable=="group_orientation" & group==0
	replace group_member_descr="Left" if variable=="group_orientation" & group==1
	replace group_member_descr="Center" if variable=="group_orientation" & group==2
	replace group_member_descr="Right" if variable=="group_orientation" & group==3

	replace group_member_descr="Political interest:" if variable=="group_interest" & group==0
	replace group_member_descr="Rather interested" if variable=="group_interest" & group==1
	replace group_member_descr="Rather not interested" if variable=="group_interest" & group==2
	
	replace group_member_descr="Trust in government:" if variable=="group_gov_trust" & group==0
	replace group_member_descr="Trust" if variable=="group_gov_trust" & group==1
	replace group_member_descr="No trust" if variable=="group_gov_trust" & group==2
	
	replace group_member_descr="Age:" if variable=="group_age" & group==0	
	replace group_member_descr="18-39" if variable=="group_age" & group==1
	replace group_member_descr="40-65" if variable=="group_age" & group==2
	replace group_member_descr=">65" if variable=="group_age" & group==3
	
	
	replace group_member_descr="Education:" if variable=="group_educ" & group==0	
	replace group_member_descr="Low" if variable=="group_educ" & group==1
	replace group_member_descr="Middle" if variable=="group_educ" & group==2
	replace group_member_descr="High" if variable=="group_educ" & group==3

	replace group_member_descr="Employment status:" if variable=="group_employed" & group==0	
	replace group_member_descr="Employed" if variable=="group_employed" & group==1
	replace group_member_descr="Unemployed" if variable=="group_employed" & group==2

	replace group_member_descr="Language:" if variable=="group_language" & group==0	
	replace group_member_descr="German" if variable=="group_language" & group==1
	replace group_member_descr="French/Italian" if variable=="group_language" & group==2

	replace group_member_descr="Religion:" if variable=="group_religion" & group==0	
	replace group_member_descr="Other" if variable=="group_religion" & group==3
	replace group_member_descr="Protestant" if variable=="group_religion" & group==1
	replace group_member_descr="Catholic" if variable=="group_religion" & group==2

	
	replace group_member_descr="Residence:" if variable=="group_urban" & group==0	
	replace group_member_descr="Urban" if variable=="group_urban" & group==1
	replace group_member_descr="Rural" if variable=="group_urban" & group==2
	
	replace group_member_descr="Income:" if variable=="group_income" & group==0	
	replace group_member_descr="Low" if variable=="group_income" & group==1
	replace group_member_descr="Middle" if variable=="group_income" & group==2
	replace group_member_descr="High" if variable=="group_income" & group==3
	
	replace group_member_descr="Party identification:" if variable=="group_party_identification" & group==0	
	replace group_member_descr="Other" if variable=="group_party_identification" & group==5
	replace group_member_descr="Leftist parties" if variable=="group_party_identification" & group==1
	replace group_member_descr="CVP" if variable=="group_party_identification" & group==2
	replace group_member_descr="FDP" if variable=="group_party_identification" & group==3
	replace group_member_descr="Rightist parties" if variable=="group_party_identification" & group==4

	
	replace group_member_descr="Political knowledge:" if variable=="group_knowledge" & group==0	
	replace group_member_descr="Low" if variable=="group_knowledge" & group==1
	replace group_member_descr="High" if variable=="group_knowledge" & group==2
	
	
	bysort variable_num: gen indi_group_descr=_n
	sort  variable_num group_member_descr postal 
	bysort variable_num group_member_descr: gen indi_group_member_descr=_n 
	
	
	sort variable_num group postal
	
	gen title="plain"
	replace title="bold" if beta==. & postal==1 // indicator for title (to make them bold in ggplot)

	
	saveold ./marginal_effects/me_postalmarginal_all.dta, replace version(12)
	
	
	
	
	
	
	*Figure 3
	 
	// groups with 2 categories


	
	local var "group_knowledge group_gender group_urban group_employed group_gov_trust group_interest group_language"
	foreach x of local var{   
	
	forvalues i=1(1)2{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)
	
		margins, at((mean)  _all postal_all=0) 
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	
	margins, at((mean)_all postal_all=1) 
	matrix beta_cov2=r(V)
	matrix beta2=r(b)'
	
	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)
	svmat beta2, names(beta2)
	svmat beta_cov2, names(beta_cov2)
				
	keep beta1 beta2 beta_cov*
	keep if beta_cov1!=.
	
	saveold ./marginal_effects/me_postal_`x'`i'.dta, replace
	}
	
	use ./marginal_effects/me_postal_`x'1.dta, clear
	forvalues i=2(1)2{
	append using ./marginal_effects/me_postal_`x'`i'.dta
		}
	gen group=_n
	order beta11 beta21 beta_cov11 beta_cov21
	saveold ./marginal_effects/me_postal_`x'_all.dta, replace
	
	}
	
	// groups with 3 categories
	
	local var "group_educ group_age  group_orientation group_religion group_orientation_alt group_participation group_party group_income"
	foreach x of local var{   


	forvalues i=1(1)3{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)

	margins, at((mean)  _all postal_all=0) 
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	
	margins, at((mean)_all postal_all=1) 
	matrix beta_cov2=r(V)
	matrix beta2=r(b)'
	
	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)
	svmat beta2, names(beta2)
	svmat beta_cov2, names(beta_cov2)
				
	keep beta1 beta2 beta_cov*
	keep if beta_cov1!=.
	
	saveold ./marginal_effects/me_postal_`x'`i'.dta, replace
	}
	
	use ./marginal_effects/me_postal_`x'1.dta, clear
	forvalues i=2(1)3{
	append using ./marginal_effects/me_postal_`x'`i'.dta
		}
	gen group=_n
	order beta11 beta21 beta_cov11 beta_cov21
	saveold ./marginal_effects/me_postal_`x'_all.dta, replace
	
	}

	// group with 5 categories
	
	
	local var "group_party_identification"
	foreach x of local var{   
	


	forvalues i=1(1)5{
	use data3.dta, clear
	
	egen abstag=group(year month day)

	probit turnout    postal_all ///
		  i.abstag i.canton   if inrange(year,1980,year_up)  & `x'==(`i')  , vce(cluster abstag)

	margins, at((mean)  _all postal_all=0) 
	matrix beta_cov1=r(V)
	matrix beta1=r(b)'
	
	margins, at((mean)_all postal_all=1) 
	matrix beta_cov2=r(V)
	matrix beta2=r(b)'
	
	svmat beta1, names(beta1)
	svmat beta_cov1, names(beta_cov1)
	svmat beta2, names(beta2)
	svmat beta_cov2, names(beta_cov2)
				
	keep beta1 beta2 beta_cov*
	keep if beta_cov1!=.
	
	
	saveold ./marginal_effects/me_postal_`x'`i'.dta, replace
	}
	

	use ./marginal_effects/me_postal_`x'1.dta, clear
	gen group=1
	forvalues i=2(1)5{
	append using ./marginal_effects/me_postal_`x'`i'.dta
	replace group=`i' if group==.
		}
	order beta11  beta_cov11 
	saveold ./marginal_effects/me_postal_`x'_all.dta, replace
	
	}
	
	
	
	
	// append all groups
	
	use ./marginal_effects/me_postal_group_party_identification_all.dta, clear

	gen variable="group_party_identification"
	local count_var=1
	
	local new = _N + 1 // add one observation for labeling of group description
    set obs `new'  
	replace group=0 if group==.
	replace variable="group_party_identification" if variable==""
	gen var_sort=1
	gen variable_num=1
	
	local var "group_orientation group_interest group_knowledge group_gov_trust group_age group_educ group_employed group_income group_language group_religion group_urban"
	foreach x of local var{   // sample restriction 1: drop all with missing values
	local count_var=`count_var' +1
	append using ./marginal_effects/me_postal_`x'_all.dta
	local new = _N + 1 // add one observation for labeling of group description
    set obs `new'  
	replace group=0 if group==.
	replace var_sort=`count_var' if var_sort==.
	replace variable="`x'" if  variable==""
	replace variable_num=`count_var' if  variable_num==.
	}
	
	rename beta11 beta1
	rename beta_cov11 beta_cov1
	
	
	gen indi=_n
	
	reshape long beta beta_cov, i(indi) j(postal)
	
	
	gsort variable_num  -group postal // generate index for y-axis of plot
	gen id=_n
	
	// labeling
	
	gen group_description=""
	replace group_description="Ideology" if variable=="group_orientation"
	replace group_description="Political interest" if variable=="group_interest"
	replace group_description="Political knowledge" if variable=="group_knowledge"
	replace group_description="Trust in government" if variable=="group_gov_trust"
	replace group_description="Age" if variable=="group_age"
	replace group_description="Education" if variable=="group_educ"
	replace group_description="Employment status" if variable=="group_employed"
	replace group_description="Language" if variable=="group_language"
	replace group_description="Religion" if variable=="group_religion"
	replace group_description="Residence" if variable=="group_urban"
	replace group_description="Income" if variable=="group_income"
	replace group_description="Party identification" if variable=="group_party_identification"


	gen group_member_descr=""
	replace group_member_descr="Ideology:" if variable=="group_orientation" & group==0
	replace group_member_descr="Left" if variable=="group_orientation" & group==1
	replace group_member_descr="Center" if variable=="group_orientation" & group==2
	replace group_member_descr="Right" if variable=="group_orientation" & group==3

	replace group_member_descr="Political interest:" if variable=="group_interest" & group==0
	replace group_member_descr="Rather interested" if variable=="group_interest" & group==1
	replace group_member_descr="Rather not interested" if variable=="group_interest" & group==2
	
	replace group_member_descr="Trust in government:" if variable=="group_gov_trust" & group==0
	replace group_member_descr="Trust" if variable=="group_gov_trust" & group==1
	replace group_member_descr="No trust" if variable=="group_gov_trust" & group==2
	
	replace group_member_descr="Age:" if variable=="group_age" & group==0	
	replace group_member_descr="18-39" if variable=="group_age" & group==1
	replace group_member_descr="40-65" if variable=="group_age" & group==2
	replace group_member_descr=">65" if variable=="group_age" & group==3
	
	
	replace group_member_descr="Education:" if variable=="group_educ" & group==0	
	replace group_member_descr="Low" if variable=="group_educ" & group==1
	replace group_member_descr="Middle" if variable=="group_educ" & group==2
	replace group_member_descr="High" if variable=="group_educ" & group==3

	replace group_member_descr="Employment status:" if variable=="group_employed" & group==0	
	replace group_member_descr="Employed" if variable=="group_employed" & group==1
	replace group_member_descr="Unemployed" if variable=="group_employed" & group==2

	replace group_member_descr="Language:" if variable=="group_language" & group==0	
	replace group_member_descr="German" if variable=="group_language" & group==1
	replace group_member_descr="French/Italian" if variable=="group_language" & group==2

	replace group_member_descr="Religion:" if variable=="group_religion" & group==0	
	replace group_member_descr="Other" if variable=="group_religion" & group==3
	replace group_member_descr="Protestant" if variable=="group_religion" & group==1
	replace group_member_descr="Catholic" if variable=="group_religion" & group==2

	
	replace group_member_descr="Residence:" if variable=="group_urban" & group==0	
	replace group_member_descr="Urban" if variable=="group_urban" & group==1
	replace group_member_descr="Rural" if variable=="group_urban" & group==2
	
	replace group_member_descr="Income:" if variable=="group_income" & group==0	
	replace group_member_descr="Low" if variable=="group_income" & group==1
	replace group_member_descr="Middle" if variable=="group_income" & group==2
	replace group_member_descr="High" if variable=="group_income" & group==3
	
	replace group_member_descr="Party identification:" if variable=="group_party_identification" & group==0	
	replace group_member_descr="Other" if variable=="group_party_identification" & group==5
	replace group_member_descr="Leftist parties" if variable=="group_party_identification" & group==1
	replace group_member_descr="CVP" if variable=="group_party_identification" & group==2
	replace group_member_descr="FDP" if variable=="group_party_identification" & group==3
	replace group_member_descr="Rightist parties" if variable=="group_party_identification" & group==4

	
	replace group_member_descr="Political knowledge:" if variable=="group_knowledge" & group==0	
	replace group_member_descr="Low" if variable=="group_knowledge" & group==1
	replace group_member_descr="High" if variable=="group_knowledge" & group==2
	

		
	bysort variable_num: gen indi_group_descr=_n
	sort  variable_num group_member_descr postal 
	bysort variable_num group_member_descr: gen indi_group_member_descr=_n 
	
	
	sort variable_num group postal
	
	gen title="plain"
	replace title="bold" if beta==. & postal==1 // indicator for title (to make them bold in ggplot)
	replace postal=2 if postal==21

	
	saveold ./marginal_effects/me_postal_all.dta, replace version(12)
	